<template>
	<view style="width: 100%;background-color: #112858;height: 100vh;overflow-y: auto;">
		<view class="gundong" style="width: 100%;background: rgb(13, 46, 100);margin-top: 20rpx; padding: 20rpx;">
			<view class="flex p-xs margin-bottom-sm mb-sm">
				<view class="flex-sub padding-sm margin-xs radius"
					style="width: 56% !important;padding-left: 0 !important;">
					<view style="font-size: 25rpx;color: #b1c2d7;">{{item.createtime}}</view>
				</view>
			</view>
			<view class="flex p-xs margin-bottom-sm mb-sm" style="margin-top: -50rpx;">
				<view class="flex-sub padding-sm margin-xs radius rich-text-container" style="width: 98%;">
					<rich-text selectable="true" class="rich-text"
						style="width: 98%;font-size: 30rpx;color: white;overflow: hidden; text-overflow: ellipsis;"
						:nodes="item.content"></rich-text>
				</view>
			</view>
			<view>
				<view v-for="(img,img_index) in item.file_img" :key="img_index"
					v-if="item.file_img && item.file_img.length > 0"
					style="display: inline-block;width: 30%;height: 180rpx;padding: 0 10rpx;">
					<image style="width: 100%;height: 100%;margin-left: 30rpx;"
						:src="img" mode="aspectFill" @click="tankuang(img,item.file_img)"></image>
				</view>
			</view>
			<view style="display: flex; justify-content: center; align-items: center;"
				v-for="(video,index) in item.file_video" :key="index">
				<video :src="video"></video>
			</view>
			<view v-for="(datafile,ind) in item.file_data" :key="ind">
				<view
					style="color:#26c3dd; padding:10rpx 0 10rpx 20rpx;overflow: hidden;word-wrap: break-word;word-break: break-all;"
					@click="downloadFiles(ind,datafile)">
					{{datafile.filename}}
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				item: [],
			}
		},
		onLoad(options) {
			this.item = JSON.parse(options.item)
			console.log(this.item)
		},
		methods: {
			//下载附件
			downloadFiles(index, datafile) {
				const url = datafile.url; // 替换为实际文件的URL
				const fileName = datafile.filename; // 替换为实际文件的名称
				const res = uni.downloadFile({
					url: url,
					success: (downloadResult) => { // 使用箭头函数
						if (downloadResult.statusCode === 200) {
							const tempFilePath = downloadResult.tempFilePath
							console.log(tempFilePath, 888)
							uni.showToast({
								title: '下载成功',
								icon: 'success'
							})
							this.openTempFile(tempFilePath) // 此处的this仍然指向downloadFiles函数
						} else {
							console.error('文件下载失败')
						}
					},
					fail: (error) => { // 使用箭头函数
						console.error('文件下载失败', error)
					}
				})
				res.onProgressUpdate((progress) => {
					console.log('下载进度：' + progress.progress)
				})
			},
			openTempFile(url) {
				wx.openDocument({
					filePath: url,
					success: (res) => { // 使用箭头函数
						console.log('临时文件打开成功')
					},
					fail: (error) => { // 使用箭头函数
						console.error('打开临时文件失败', error)
					}
				})
			},
		}
	}
</script>

<style>

</style>
